package day04

/**
  * 上界 UpperBound
  */
class UpperBoundDemo[T <: Comparable[T]] {
  def select(first: T, senond: T): T = {
    if (first.compareTo(senond) > 0) {
      first
    } else {
      senond
    }
  }
}

object UpperBoundDemo {
  def main(args: Array[String]): Unit = {
    val upperBound: UpperBoundDemo[MyGoddess] = new UpperBoundDemo[MyGoddess]
    val zhangsan: MyGoddess = MyGoddess("zhangsan",90)
    val lisi: MyGoddess = MyGoddess("lisi",94)
    val goddess: MyGoddess = upperBound.select(zhangsan,lisi)
    println(goddess)
  }
}

class MyGoddess(val name: String, val faceValue: Int) extends Comparable[MyGoddess] {
  override def compareTo(o: MyGoddess): Int = {
    this.faceValue - o.faceValue
  }

  override def toString = s"MyGoddess($name, $faceValue)"
}

object MyGoddess {
  def apply(name: String, faceValue: Int): MyGoddess = new MyGoddess(name, faceValue)
}